//
//  CellForTravel.m
//  ProjectA
//
//  Created by dllo on 16/3/11.
//  Copyright © 2016年 刘旺辉. All rights reserved.
//

#import "CellForTravelTabView.h"
#import "AppMacro.h"
#import "NSString+HeightLabel.h"
#import "ModelForTravelTabViewCell.h"
#import <UIImageView+WebCache.h>
@interface CellForTravelTabView ()
@property (nonatomic, strong) UIView *viewForLine;
@property (nonatomic, strong) UIView *view;
@property (nonatomic, strong) UIImageView *imageViewForPhoto;
@property (nonatomic, strong) UILabel *labelForText;
@property (nonatomic, strong) ModelForTravelTabViewCell *model;
@property (nonatomic, strong) UILabel *labelForTime;
@end

@implementation CellForTravelTabView
- (void)dealloc {
    [_labelForTime release];
    [_model release];
    [_labelForText release];
    [_imageViewForPhoto release];
    [_view release];
    [_viewForLine release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.viewForLine = [[UIView alloc] init];
        [self.contentView addSubview:self.viewForLine];
        [_viewForLine release];
    
        self.view = [[UIView alloc] init];
        [self.contentView addSubview:self.view];
        [_view release];
        self.view.layer.shadowOffset = CGSizeMake(2, 2);
        self.view.layer.shadowColor = [[UIColor grayColor] CGColor];
        self.view.layer.shadowRadius = 2;
        self.view.layer.shadowOpacity = 1;
        
        self.imageViewForPhoto = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageViewForPhoto];
        [_imageViewForPhoto release];
        
        
        self.labelForText = [[UILabel alloc] init];
        [self.contentView addSubview:self.labelForText];
        [_labelForText release];
        self.labelForText.font = [UIFont systemFontOfSize:15];
        
        
        self.labelForText.numberOfLines = 0;
        
        self.labelForTime = [[UILabel alloc] init];
        [self.contentView addSubview:self.labelForTime];
        [_labelForTime release];
        self.labelForTime.font = [UIFont systemFontOfSize:13];
    }
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.viewForLine.frame = CGRectMake(self.bounds.size.width / 18.f, 0, self.bounds.size.width / 70.f, self.bounds.size.height);
    self.labelForText.text = self.model.text;
    self.labelForTime.text = self.model.local_time;
    
    // 照片自适应高度
    if (![self.model.photo_1600 isEqualToString:@""]) {
        
        self.imageViewForPhoto.frame = CGRectMake(10, 10, self.contentView.bounds.size.width - 20, [NSString heightForImageSetHeight:[[self.model.photo_info objectForKey:@"h"] floatValue] setWidth:[[self.model.photo_info objectForKey:@"w"] floatValue] getWidth:self.contentView.bounds.size.width - 20]);
        [self.imageViewForPhoto sd_setImageWithURL:[NSURL URLWithString:self.model.photo_1600] placeholderImage:[UIImage imageNamed:@"iconfont-zhanweitu"]];
        
        // 文本自适应(判断是否有text)
        if ([self.labelForText.text isEqualToString:@""]) {
            self.labelForText.frame = CGRectZero;
            self.labelForTime.frame = CGRectMake(20, self.imageViewForPhoto.frame.size.height + 10 + 10, self.bounds.size.width - 40, 15);
        } else {
            
            self.labelForText.frame = CGRectMake(20, self.imageViewForPhoto.bounds.size.height + 10 + 10, self.contentView.bounds.size.width - 40, [NSString heightForLabel:self.labelForText.text withWidth:self.contentView.bounds.size.width - 40 withEdge:0 withFontOfSize:15]);
            
            self.labelForTime.frame = CGRectMake(20, self.labelForText.frame.size.height + self.imageViewForPhoto.bounds.size.height + 10 + 10 + 10, self.bounds.size.width - 40, 15);
            
        }

    } else {
        
        self.imageViewForPhoto.frame = CGRectZero;
        
        // 文本自适应(判断是否有text)
        if ([self.labelForText.text isEqualToString:@""]) {
            self.labelForText.frame = CGRectZero;
            self.labelForTime.frame = CGRectMake(20, 10 + 10, self.bounds.size.width - 40, 15);
        } else {
            
            self.labelForText.frame = CGRectMake(20, 10 + 10, self.contentView.bounds.size.width - 40, [NSString heightForLabel:self.labelForText.text withWidth:self.contentView.bounds.size.width - 40 withEdge:0 withFontOfSize:15]);
            
            self.labelForTime.frame = CGRectMake(20, self.labelForText.frame.size.height + 10 + 10 + 10, self.bounds.size.width - 40, 15);
        }
    }
   
    
    
    
    
    // 白色背景frame设定
    self.view.frame = CGRectMake(10, 10, self.bounds.size.width - 20, self.bounds.size.height - 20);
    
    
    [UIView setColorWithView:self.viewForLine nightColor:L_COLOR_WHITE dayColor:RGBA(172, 135, 79, 1)];
    [UIView setColorWithLabelText:self.labelForText nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    [UIView setColorWithLabelText:self.labelForTime nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    [UIView setColorWithView:self.view nightColor:L_COLOR_LIGHTGRAY dayColor:L_COLOR_WHITE];
}
- (void)passData:(ModelForTravelTabViewCell *)model {
    
    self.model = model;
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
